package io.gitee.caoxiaoyu97;

import freemarker.template.TemplateException;
import io.gitee.caoxiaoyu97.messageconvert.client.CxyCloudAdapterClientUtil;
import io.gitee.caoxiaoyu97.messageconvert.client.customer.CxyCloudAdapterServiceUtil;
import io.gitee.caoxiaoyu97.messageconvert.common.CxyCloudTempConfigurationUtil;
import io.gitee.caoxiaoyu97.messageconvert.server.CxyCloudGateWayServerUtil;
import io.gitee.caoxiaoyu97.messageconvert.server.service.CxyCloudGateWayServiceMetadata;
import io.gitee.caoxiaoyu97.messageconvert.server.service.CxyCloudGateWayServiceUtil;

import java.io.IOException;

/*********************************************************
 * 文件名称：${NAME}.java
 * 系统名称：CXY自定义系统
 * 模块名称：io.gitee.caoxiaoyu97
 * 功能说明：${TODO}
 * 开发人员 @author：caoxy31978
 * 开发时间 @date：${DATE} ${TIME}
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class Main {
    public static void main(String[] args) throws TemplateException, IOException, InterruptedException {
        // serverTest();
        clientTest();
    }

    private static void clientTest() {
        CxyCloudAdapterClientUtil.init("messageconvert/client");
        String s = CxyCloudAdapterServiceUtil.invokeService("001", "{'req':'req1'}");
        System.out.println(s);
        s = CxyCloudAdapterServiceUtil.invokeService("002", "{'req':'req1'}");
        System.out.println(s);
    }

    private static void serverTest() {
        CxyCloudGateWayServerUtil.init("/messageconvert/server");
        String response1 = CxyCloudGateWayServiceUtil.invokeService("XXX1", "{'req':'req1'}");
        System.out.println(response1);
        String response2 = CxyCloudGateWayServiceUtil.invokeService("XXX2", "{'req':'reqmock'}");
        System.out.println(response2);
        CxyCloudGateWayServiceMetadata metadata = CxyCloudGateWayServerUtil.getAllServices().get("XXX1");
        metadata.setReqTemp("{'reqStrxxx':'${req.req} & ${ext.reqext!} & ${ext.respext!}'}");
        CxyCloudTempConfigurationUtil.updateTemp(metadata);
        response1 = CxyCloudGateWayServiceUtil.invokeService("XXX1", "{'req':'req1'}");
        System.out.println(response1);
    }

    public static String getOne(){
        return "one";
    }
}